package testWork;

import org.junit.Test;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by cdxuhongya on 2016/11/29.
 */
public class test {

    @Test
    public void test(){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date cmpDate = new Date();
        try {
            cmpDate =  sdf.parse("2016-10-15");
        }catch (ParseException p){

        }
        int i = 0;
        i++;
    }


    @Test
    public void testDate(){
        validateDateSpan("2016-10-10","2016-12-23");

    }

    private boolean validateDateSpan(String beginDateStr, String endDateStr){
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            Date beginDate =  sdf.parse(beginDateStr);
            Date endDate = sdf.parse(endDateStr);
            Date nowDate = new Date();
            if(nowDate.getTime() <=  endDate.getTime() && nowDate.getTime() >= beginDate.getTime()){
                return true;
            }

            return false;
        }catch (Exception e){
            return  false;
        }
    }
}
